package com.xyy.saas.payment.payment.core.dto;

import com.xyy.saas.payment.common.exception.PaymentException;
import com.xyy.saas.payment.cores.enums.ResultCodeEnum;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

@Getter
@Setter
@Builder
public class WithdrawAuthDto {
    /**
     * 业务线
     */
    private String businessIdType;
    /**
     * 支付平台提现单号
     */
    private String withdrawalNo;
    /**
     * 渠道提现单号
     */
    private String channelWithdrawNo;
    /**
     * 验证码
     */
    private String activeCode;
    /**
     * 支付平台商户ID
     */
    private String accountId;

    /**
     * 参数校验
     */
    public static void checkParam(WithdrawAuthDto withdrawAuthDto) throws PaymentException {
        if(withdrawAuthDto == null) {
            throw new PaymentException(ResultCodeEnum.PARAM_ERROR.getCode(), "withdrawAuthDto|不能为空");
        }

        if(StringUtils.isBlank(withdrawAuthDto.getBusinessIdType())) {
            throw new PaymentException(ResultCodeEnum.PARAM_ERROR.getCode(), "businessIdType|不能为空");
        }

        if(StringUtils.isBlank(withdrawAuthDto.getWithdrawalNo())) {
            throw new PaymentException(ResultCodeEnum.PARAM_ERROR.getCode(), "withdrawalNo|不能为空");
        }

        if(StringUtils.isBlank(withdrawAuthDto.getChannelWithdrawNo())) {
            throw new PaymentException(ResultCodeEnum.PARAM_ERROR.getCode(), "channelWithdrawNo|不能为空");
        }

        if(StringUtils.isBlank(withdrawAuthDto.getActiveCode())) {
            throw new PaymentException(ResultCodeEnum.PARAM_ERROR.getCode(), "activeCode|不能为空");
        }

        if(withdrawAuthDto.getActiveCode().length() != 6) {
            throw new PaymentException(ResultCodeEnum.PARAM_ERROR.getCode(), "验证码长度为6，请确认后重试");
        }

        if(StringUtils.isBlank(withdrawAuthDto.getAccountId())) {
            throw new PaymentException(ResultCodeEnum.PARAM_ERROR.getCode(), "accountId|不能为空");
        }
    }
}
